package com.rdk.service.impl;


import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.rdk.dao.TShareUserRelationMapper;
import com.rdk.entity.TShareUserRelation;
import com.rdk.service.TShareUserRelationService;
import com.rdk.utils.BusinessException;

@Service
public class TShareUserRelationServiceImpl extends BaseServiceImpl<TShareUserRelation>  implements TShareUserRelationService {
	@Autowired
	private TShareUserRelationMapper mapper;

	public void saveShareScope(String shareId, String userId, String scope, String groupId) throws BusinessException {
        if ("public".equals(scope)) {
            TShareUserRelation relation = new TShareUserRelation();
            relation.setShareId(shareId);
            relation.setUserId("-1");
            relation.setType("2");
            mapper.insertSelective(relation);
        } else if ("private".equals(scope)) {
            TShareUserRelation relation = new TShareUserRelation();
            relation.setShareId(shareId);
            relation.setUserId(userId);
            relation.setType("1");
            mapper.insertSelective(relation);
        } else {
            String type = "enable".equals(scope) ? "1" : "2";
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("type", type);
            map.put("shareId", shareId);
            map.put("groupId", groupId);
            mapper.insertEnable(map);
        }
    }
}